package cn.openea.perpartner.meily.web.controller;



import cn.openea.perpartner.common.core.web.controller.BaseController;
import cn.openea.perpartner.common.core.web.domain.AjaxResult;
import cn.openea.perpartner.common.core.web.page.TableDataInfo;
import cn.openea.perpartner.meily.util.UserContext;
import cn.openea.perpartner.meily.web.entity.Notice;
import cn.openea.perpartner.meily.web.service.INoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * (Notice)表控制层
 *
 * @author Weird077
 * @since 2023-01-11 11:17:22
 */
@Api(tags = "公告管理")
@RestController
@RequestMapping("/notice")
public class NoticeController extends BaseController {

    @Resource
    private INoticeService noticeService;
    @ApiOperation("公告列表")
    @PostMapping("/list")
    public TableDataInfo selectAll(@RequestBody Notice notice) {
        startPage();
        List<Notice> list = this.noticeService.selectList(notice);
        return getDataTable(list);
    }
    @ApiOperation("最新公告")
    @PostMapping(value = "/last",produces = "application/json;charset=UTF-8")
    public TableDataInfo getLastOne() {
        startPage();
        List<Notice> list = this.noticeService.getLastOne();
        return getDataTable(list);
    }
    @ApiOperation("公告详情")
    @GetMapping("{id}")
    public AjaxResult selectOne(@PathVariable Serializable id) {
        return success(this.noticeService.getById(id));
    }

    @ApiOperation("新增公告")
    @PostMapping("/add")
    public AjaxResult insert(@RequestBody Notice notice) {
        notice.setCreateUser(UserContext.getUserId());
        return toAjax(this.noticeService.save(notice));
    }
    @ApiOperation("修改公告")
    @PostMapping("/edit")
    public AjaxResult update(@RequestBody Notice notice) {
        notice.setUpdateUser(UserContext.getUserId());
        return toAjax(this.noticeService.updateById(notice));
    }

    @ApiOperation("删除公告")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody List<Long> idList) {
        return success(this.noticeService.removeBatchByIds(idList));
    }
}

